<?php
/**
 * wmfl.cn version 5.0
 * -----------------------------------------------
 * @author sy <409014125@qq.com>
 * @link http://www.utuo88.com
 * @copyright 2014 Utuo Tech co.,Ltd
 */
namespace Partner\Model;
use Think\Model;
/**
 * 客户行为模型
 * @author huajie <banhuajie@163.com>
 */
class CustomerModel extends Model {
	
	const TYPE_STANDARD = 0; // 标准客户
	const TYPE_AGENT = 1; // 代理商客户
	
	protected $_validate = array(
			array('name','require','客户姓名必须',self::MUST_VALIDATE),
			array('email','','客户Email已经存在',self::EXISTS_VALIDATE, 'unique'),
			array('email','email','客户Email格式不正确',self::EXISTS_VALIDATE),
			//array('tel', '/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/', '手机格式不正确', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH), //手机格式不正确 
	);
	
	protected $_auto = array(
		
		array('last_login_time', 'time', self::MODEL_UPDATE, 'function'),
		array('last_login_ip', 'get_client_ip', self::MODEL_UPDATE, 'function'),
		array('begin_time', 'strtotime', self::MODEL_BOTH, 'function'),
		array('end_time', 'strtotime', self::MODEL_BOTH, 'function'),
	);
	
	// 可查询的字段(字段以查询sql语句的字段为准)
	public $searchFields = array(
		'f0' => array('this0.name','客户姓名'),
		'f1' => array('this0.partnerName','所属合作商'),
		'f2' => array('this0.tel','联系人电话'),
		'f3' => array('this0.contacts','联系人'),
	);
	
	// 获得查询字段KV
	public function getSearchKV(){
		$data = array();
		foreach($this->searchFields as $k => $v){
			$data[$k] = $v[1];
		}
		return $data;
	}
	public function getPassword() {
		$password = I("password");
		if(!isset($_REQUEST['password']) or empty($password)) return false;
		return hash_pwd($password);
	}
}